package com.corpcredit.webapp.action;

import java.io.Serializable;
import java.util.Date;

import com.corpcredit.Constants;
import com.corpcredit.model.GlryGzjl;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class GlryGzjlForm extends BasePage implements Serializable {
    private GenericManager<GlryGzjl, Long> glryGzjlManager;
    private GlryGzjl glryGzjl = new GlryGzjl();
    private Long id;

    public void setGlryGzjlManager(GenericManager<GlryGzjl, Long> glryGzjlManager) {
        this.glryGzjlManager = glryGzjlManager;
    }

    public GlryGzjl getGlryGzjl() {
        return glryGzjl;
    }

    public void setGlryGzjl(GlryGzjl glryGzjl) {
        this.glryGzjl = glryGzjl;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        glryGzjlManager.remove(glryGzjl.getId());
        addMessage("glryGzjl.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            glryGzjl = glryGzjlManager.get(id);
        } else {
            glryGzjl = new GlryGzjl();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (glryGzjl.getId() == null || glryGzjl.getId() == 0);
        
        //dwtz.setJbqk(jbqk);
        glryGzjl.setUsername(getRequest().getRemoteUser());
        glryGzjl.setOptdate(new Date());
        glryGzjl.setOperation(isNew?Constants.OPERATION_ADD:Constants.OPERATION_UPDATE);
        

        
        glryGzjlManager.save(glryGzjl);

        String key = (isNew) ? "glryGzjl.added" : "glryGzjl.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
        	 this.id=this.glryGzjl.getId();
             return edit();

        }
    }
} 